import { defHttp } from '/@/utils/http/axios';
import {
 ${entity}ListGetResultModel,
 ${entity}Model,
 ${entity}PageListGetResultModel,
 ${entity}Params,
 ${entity}PageSearchParams,
 ${entity}ListSearchParams,
 Update${entity}Params,
 ${entity}IDType,
} from '/@/api<#if package.ModuleName??>/${package.ModuleName}</#if>/model/${entity}Model';

import { UploadFileParams } from '/#/axios';
import { useGlobSetting } from '/@/hooks/setting';
import { UploadApiResult } from '../sys/model/uploadModel';

<#if customTableInfo.businessName!?length gt 0>
// ${customTableInfo.businessName}接口
<#elseif customTableInfo.tableComment!?length gt 0>
// ${customTableInfo.businessName}接口
</#if>
export enum Api {
    PublicApi = '<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>',
    ListApi = `<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>/list`,
    PageApi = `<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>/page`,
    BatchApi = `<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>/batch`,
    ExportApi = `<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>/export`,
    ImportApi = `<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>/import`,
}
/**
 * @description:  获取列表
 * @param params
 * @returns
 */
export const get${entity}List = (params?: ${entity}ListSearchParams) =>
   defHttp.get<${entity}ListGetResultModel>({ url: Api.ListApi, params });

/**
 * @description:  分页获取列表
 * @param params
 * @returns
 */
export const get${entity}Page = (params: ${entity}PageSearchParams) =>
  defHttp.get<${entity}PageListGetResultModel>({ url: Api.PageApi, params });

/**
 * @description:  根据id获取
 * @param id
 * @returns
 */
export const get${entity} = (id: ${entity}IDType) =>
  defHttp.get<${entity}Model>({ url: `${r'${Api.PublicApi}/${id}'}` });

/**
 * @description:  创建
 * @param params
 * @returns
 */
export const create${entity} = (params: ${entity}Params) =>
  defHttp.post<boolean>({ url: Api.PublicApi, params });

/**
 * @description:  更新
 * @param params
 * @returns
 */
export const update${entity} = (params: Update${entity}Params) =>
  defHttp.put<boolean>({ url: Api.PublicApi, params });

/**
 * @description:  物理删除
 * @param id
 * @returns
 */
export const delete${entity} = (id: ${entity}IDType) =>
  defHttp.delete<boolean>({ url: `${r'${Api.PublicApi}/${id}'}` });

/**
 * @description:  物理批量删除
 * @param ids
 * @returns
 */
export const delete${entity}Batch = (ids: ${entity}IDType[]) =>
  defHttp.post<boolean>({ url: Api.BatchApi, params: { ids } });

/**
 * @description:  逻辑删除
 * @param ids
 * @returns
 */
export const logicDelete${entity} = (id: ${entity}IDType) =>
  defHttp.delete<boolean>({ url: `${r'${Api.PublicApi}/${id}'}` });

/**
 * @description:  逻辑批量删除
 * @param ids
 * @returns
 */
export const logicDelete${entity}Batch = (ids: ${entity}IDType[]) =>
  defHttp.post<boolean>({ url: Api.BatchApi, params: { ids } });

/**
* @description:  导出文件
* @param ids
* @returns
*/
export const export${entity}ListFile = (ids: ${entity}IDType[]) =>
defHttp.post<boolean>({ url: Api.ExportApi, params: { ids } });

/**
* @description:  导入文件
* @param ids
* @returns
*/
export const import${entity}ListFile = (
params: UploadFileParams,
onUploadProgress?: (progressEvent: ProgressEvent) => void,
) =>
defHttp.uploadFile<UploadApiResult>(
{
  url: useGlobSetting().apiUrl + Api.ImportApi,
  onUploadProgress,
}, params);
